#region (c) 2014 THN Solutions LLC. - All rights reserved
/*
THN TELEPORT version 2

Copyright (c) 2014, THN Solutions LLC. ( www.ThnSolutions.com )
Author: Nguyễn, M. Hải                 ( www.Minh-Hai.com     )
All rights reserved.

This library is dual-licensed.
  + For commercial software, please obtain a commercial license from THN Solutions LLC.

  + For free software, this library is licensed under GPL version 3. A summary of GPLv3 is
    listed below. You should also find a copy of GPLv3 as file License_GPLv3.txt included
	with the source-code files.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License version 3 as published by
    the Free Software Foundation  of the License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#endregion

#region Record of Change
//             							CHANGE HISTORY
// -------------------------------------------------------------------------------------
// |   DATE    | DEVELOPER  | DESCRIPTION                                              |
// -------------------------------------------------------------------------------------
// | 21-Apr-09 | HaiNM      | First creation.                                          |
// -------------------------------------------------------------------------------------
//
#endregion

#region Record of Audit
//             							REVIEW HISTORY
// -------------------------------------------------------------------------------------
// |   DATE    | REVIEWER   | NOTES                                                    |
// -------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
//
#endregion

#region Using directives
using System;

using Thn;
#endregion

namespace Demo.Business
{
    /// <summary>
    /// Sample product object
    /// </summary>
    public class Product
    {
        #region ID
        private Guid mID = Nulls.Guid;
        /// <summary>
        /// Gets/Sets ID
        /// </summary>
        [Savable]
        public Guid ID
        {
            get { return mID; }
            set { mID = value; }
        }
        #endregion

        #region Name
        private string mName = string.Empty;
        /// <summary>
        /// Gets/Sets Name
        /// </summary>
        [Savable]
        public string Name
        {
            get { return mName; }
            set { mName = value; }
        }
        #endregion

        #region Price
        private decimal mPrice = 0;
        /// <summary>
        /// Gets/Sets Price
        /// </summary>
        [Savable]
        public decimal Price
        {
            get { return mPrice; }
            set { mPrice = value; }
        }
        #endregion

        #region On Hand
        private int mOnHand = 0;
        /// <summary>
        /// Gets/Sets OnHand
        /// </summary>
        [Savable]
        public int OnHand
        {
            get { return mOnHand; }
            set { mOnHand = value; }
        }
        #endregion

        #region Last Purchase
        private DateTime mLastPurchase = Nulls.DateTime;
        /// <summary>
        /// Gets/Sets LastPurchase
        /// </summary>
        [Savable]
        public DateTime LastPurchase
        {
            get { return mLastPurchase; }
            set { mLastPurchase = value; }
        }
        #endregion

        #region Create Random
        /// <summary>
        /// Create a new instance with random data
        /// </summary>
        public static Product CreateRandom()
        {
            Product result = new Product();
            Random ran = new Random((int)DateTime.Now.Ticks);
            result.ID = Guid.NewGuid();
            result.Name = "Random product #" + ran.Next(1000).ToString();
            result.Price = (decimal)ran.Next(1000) / (decimal)10.0;
            result.OnHand = ran.Next(1000);
            result.LastPurchase = DateTime.Now
                                .AddDays(ran.Next(10))
                                .AddMonths(ran.Next(10))
                                .AddYears(ran.Next(10) - 5);

            return result;
        }
        #endregion

        #region Create Random List
        /// <summary>
        /// Create a random list of products.
        /// </summary>
        public static ProductList CreateRandomList()
        {
            ProductList result = new ProductList();
            Random ran = new Random((int)DateTime.Now.Ticks);
            int count = ran.Next(10) + 3;
            for (int i = 0; i < count; i++)
            {
                result.Add(Product.CreateRandom());
            }

            return result;
        }
        #endregion

        #region To String
        /// <summary>
        /// Converts to display text.
        /// </summary>
        public override string ToString()
        {
            return string.Format("Name: {0} Price: {1} OnHand: {2} LastPurchase: {3} ID: {4}", mName, mPrice, mOnHand, mLastPurchase, mID);
        }
        #endregion

        #region Constructors
        /// <summary>
        /// Default constructor
        /// </summary>
        public Product() 
        { }
        #endregion
    }
}
